function amisUploaderHandle() {
    const Status = [
        {
            color: '#ed7961',
            text: '请点击添加按钮选择文件'
        },
        {
            color: '#409eff',
            text: '等待上传'
        },
        {
            color: '#f56c6c',
            text: '上传失败,请重新上传'
        },
        {
            color: '#e6a23c',
            text: '请删除后重新添加'
        }
    ]

    function getNowFormatDate(date) {
    var seperator1 = '-'
    var seperator2 = ':'
    var month = date.getMonth() + 1
    var strDate = date.getDate()
    if (month >= 1 && month <= 9) {
        month = '0' + month
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
    }
    var currentdate =
        date.getFullYear() +
        seperator1 +
        month +
        seperator1 +
        strDate +
        ' ' +
        date.getHours() +
        seperator2 +
        date.getMinutes() +
        seperator2 +
        date.getSeconds()
    return currentdate
}

function upload(value, cb) {
    let self = {
        uploaderList: value ? value.split(',').map(item=>{ return{  fileId: item}}) : [],
        loading: false,
        status: Status[0],
        percentage: 0,
        uploaderStatus: false,
        result: {
            name: '',
            size: '',
            regex: '',
            fileId: ''
        }
    }
    var object = {
        self: self,
        picker: '#picker',
        ctlBtn: '#ctlBtn',
        deletBtn: 'deletBtn',
        thelist: '#thelist',
        progressLi: '#progressbar',
        chunkSize: 2 * 1024 * 1024,
        md5Url: '/fms/api/checkFileMd5',
        appId: 'app008',
        server: '/fms/api/upload/max',
        mimeTypes: 'video/*',
        thelistContent(file) {
            $('#fileList').append(`<div class="content" id="${file.id}"><p><img src="/admin/webuploader-0.1.5/img/wj.png" /><a id="filename">${file.name}</a> <img id="${file.id}-deletBtn" class="delete"   src="/admin/webuploader-0.1.5/img/delete.png" /></p><div><div id="${file.id}-progressbar"></div><img src="/admin/webuploader-0.1.5/img/dui.png"  style="display: none"/></div></div>`)
        },
        md5Error(data) {
            cb(self.result.fileId)
        },
        uploaderSuccess(status, text, fileId, data) {
            self.uploaderList.push({
                name: data.name,
                size: data.size,
                regex: data.ext,
                fileId: fileId
            })
            cb(self.uploaderList.map(item=>item.fileId).join(','))
        },
        uploaderError() {
            cb(self.uploaderList.map(item=>item.fileId).join(','))
        },
        deleteFile(file) {
            let index = self.uploaderList.findIndex(item=>item.fileId===file.fileId)
            self.uploaderList.splice(index, 1)
            $('#fileList').find(`#${file.id}`).remove()
            cb(self.uploaderList.map(item=>item.fileId).join(','))
        }
    }
    webUploaderBegin(object)
}

function customUploader(dom, value, onChange) {
    const div = document.createElement('div');
    div.className="web-uloader-main"
    div.id = "el-app"
    div.innerHTML = `<div><div id="picker" class="upload-btn" /> </div> <div id="fileList"></div>`
    dom.appendChild(div);
    setTimeout(()=>{
        upload(value, onChange)
    },500)

}

function customUpdateUploader(dom, data, prevData) {
    console.log(dom, data, prevData)
}
 return {
     customUploader,
     customUpdateUploader
 }
}
var amisUploader = amisUploaderHandle()
